# Gilardi, Fabrizio, "The Temporary Importance of Role Models for Women's Political Representation", American Journal of Political Science
# Code to replicate Table 1 (Poisson regression coefficients and standard errors)
# gilardi@ipz.uzh.ch, 2014-06-23

# Set working directory
setwd("../Data/")

# Load packages
library(texreg)

# Load data
d <- read.csv("dataset-full.csv")


###################
# Estimate models #########################################
###################

out.1 <- glm(n.women.cand ~ sl.autob.n.women.elected + n.women.elected.lagged + n.women.cand.previously.elected + n.men.cand.previously.elected + n.women.cand.lagged + n.people.elected + n.cand + referenda + wom.kr + log.dist.zh + log.pop + kr.svp + steuerfuss + as.factor(stadt.land) + as.factor(year), data=d, family="poisson")
summary(out.1)

out.2 <- glm(n.women.cand ~ sl.autob.n.women.elected + n.women.elected.lagged + n.women.cand.previously.elected + n.men.cand.previously.elected + n.women.cand.lagged + n.people.elected + n.cand + referenda + wom.kr + log.dist.zh + log.pop +  kr.svp + steuerfuss + as.factor(stadt.land) + sl.autob.n.women.elected*as.factor(year), data=d, family="poisson")
summary(out.2)

out.3 <- glm(n.women.cand ~ sl.autob.n.women.elected + n.women.elected.lagged + n.women.cand.previously.elected + n.men.cand.previously.elected + n.women.cand.lagged + n.people.elected + n.cand + referenda + wom.kr + log.dist.zh + log.pop +  kr.svp + steuerfuss + as.factor(stadt.land) + n.women.elected.lagged*as.factor(year), data=d, family="poisson")
summary(out.3)

out.4 <- glm(n.women.cand ~ sl.autob.n.women.elected + n.women.elected.lagged + n.women.cand.previously.elected + n.men.cand.previously.elected + n.women.cand.lagged + n.people.elected + n.cand + referenda + wom.kr + log.dist.zh + log.pop +  kr.svp + steuerfuss + as.factor(stadt.land) + n.women.elected.lagged*as.factor(year) + sl.autob.n.women.elected*as.factor(year), data=d, family="poisson")
summary(out.4)

out.5 <- glm(n.women.cand ~ sl.autob.n.women.elected + n.women.elected.lagged + n.women.cand.previously.elected + n.men.cand.previously.elected + n.women.cand.lagged + n.people.elected + n.cand + referenda + wom.kr + log.dist.zh + log.pop +  kr.svp + steuerfuss + as.factor(stadt.land) + n.women.elected.lagged*as.factor(year) + sl.autob.n.women.elected*as.factor(year) + as.factor(bfsnr), data=d, family="poisson")
summary(out.5)


##############
# Make table ########################################
##############

# Some stuff to make the table look right
mm <- model.matrix(out.5)
cn <- colnames(mm)
nfe <- length(cn[26:192]) - 6


# Vector with variable names
var.names <- c(
	"(Intercept)",
	"Spatial lag",
	"Nr. xfemale elected ($t-1$)",
	"Nr. xfemale incumbent cand. ($t-1$)",
	"Nr. xmale incumbent cand. ($t-1$)",
	"Nr. xfemale cand. ($t-1$)",
	"Nr. seats",
	"Total nr. candidates",
	"Referenda on gender equality",
	"Support for xfemale in cantonal elec.",
	"Distance from Zurich (log)",
	"Population (log)",
	"Support for conservative party",
	"Tax level",
	"Suburb",
	"Countryside",
	seq(1978, 2010, 4),
	"Spatial lag $xx$ 1978",
	"Spatial lag $xx$ 1982",
	"Spatial lag $xx$ 1986",
	"Spatial lag $xx$ 1990",
	"Spatial lag $xx$ 1994",
	"Spatial lag $xx$ 1998",
	"Spatial lag $xx$ 2002",
	"Spatial lag $xx$ 2006",
	"Spatial lag $xx$ 2010",
	"Nr. xfemale elected ($t-1$) $xx$ 1978",
	"Nr. xfemale elected ($t-1$) $xx$ 1982",
	"Nr. xfemale elected ($t-1$) $xx$ 1986",
	"Nr. xfemale elected ($t-1$) $xx$ 1990",
	"Nr. xfemale elected ($t-1$) $xx$ 1994",
	"Nr. xfemale elected ($t-1$) $xx$ 1998",
	"Nr. xfemale elected ($t-1$) $xx$ 2002",
	"Nr. xfemale elected ($t-1$) $xx$ 2006",
	"Nr. xfemale elected ($t-1$) $xx$ 2010",
	seq(1, nfe)
)


# Vector with model names
model.names <- c("(1)", "(2)", "(3)", "(4)", "(5)")

# LaTeX table
texreg(list(out.1, out.2, out.3, out.4, out.5), single.row=T, center=T, dcolumn=T, custom.coef.names=var.names, custom.model.names=model.names)
